#!/opt/sysroot64/usr/bin/python3.9
# coding:utf-8
import logging
from datetime import datetime

from myhttp import HttpService
from myhttp import Response

from .service import query_all_metrics

app = HttpService('Prometheus Exporter')


@app.route('/', methods=['GET', 'POST'])
def index(*args):
    return Response('exporter')


def metrics(*args):
    return Response(query_all_metrics(), headers={"Content-Type": "text/plain; charset=utf-8"})



def run(host, port, telemetry_path, ssl_keyfile, ssl_certfile, ssl_keyfile_password, ssl_ca_file):
    app.attach(metrics, telemetry_path)
    app.start_listen(host, port, ssl_keyfile, ssl_certfile, ssl_keyfile_password, ssl_ca_file)


# uvicorn server
if __name__ == "__main__":
    run(host="0.0.0.0", port=4031, telemetry_path="/metrics",
        ssl_keyfile=None, ssl_certfile=None,ssl_keyfile_password=None, ssl_ca_file=None,
        log_level="debug")
